<?php $this->load->view('home/common/header'); ?>

<script src="http://maps.google.com/maps/api/js?sensor=false&region=Vi"></script>
<script language="javascript" src="<?php echo base_url(); ?>themes/home/javascript/tooltip2.js" type="text/javascript"></script>
<script language="javascript" src="<?php echo base_url(); ?>themes/home/javascript/markerwithlabel.js" type="text/javascript"></script>
<script language="javascript" src="<?php echo base_url(); ?>themes/home/javascript/infobox_.js" type="text/javascript"></script>

<script language="javascript" src="<?php echo base_url(); ?>themes/jwysiwyg/jquery.wysiwyg.js"></script>
<link rel="stylesheet" type="text/css"  href="<?php echo base_url(); ?>themes/jwysiwyg/jquery.wysiwyg.css" />

<style type="text/css">
	 body {
	background-color: white;
	font-family: Arial, sans-serif;
	margin: 0;
}

#map_canvas {
	width: 100%;
	height: 100%;
}

#over_map {
	position: absolute;
	top: 330px;
	right: 180px;
	z-index: 99;
}

.ui-widget .ui-widget {
	font-size: 0.7em;
}

.tooltip {
	border: thin 1px #eee;
	background-color: #FFFBF0;
	padding: 5px;
	width: 200px;
}

.labels {
	color: #FFFFFF;
	background-color: green;
	font-family: "Lucida Grande", "Arial", sans-serif;
	font-size: 9px;
	font-weight: bold;
	text-align: center;
	width: 40px;
	white-space: nowrap;
    border-radius: 10px; 
	-moz-border-radius: 10px; 
	-webkit-border-radius: 10px; 
	border: 1px solid #D71A1A;
	height:13px;
}

#userRegister td {
	padding-bottom: 5px;
}

		
</style>
	
<div id="ja-content-main" class="ja-content-main clearfix">                            
<div class="item-page"></div>	
	
<!--body start -->
		<ul id="mypopup" class="contextMenu">
		    <li class="addPlace">
		        <a href="#addPlace">Add place</a>
		    </li>
		    <li class="zoomIn separator">
		        <a href="#zoomIn">Zoom in</a>
		    </li>
		    <li class="zoomOut">
		        <a href="#zoomOut">Zoom out</a>
		    </li>
		    <li class="centerHere">
		        <a href="#centerHere">Center map</a>
		    </li>
		    <li class="quit separator">
		        <a href="#quit">Quit</a>
		    </li>
		</ul>
	
	<div id="map_canvas" style=" position: relative !important;width:100%; height: 550px;" ></div>
	
	    <div id="over_map" style="display:none;">
	 
	<table id="gwidth"></table>
	 <div id="pgwidth"></div>
	    </div>
			<div id="dialog" title="Add a place" style="font-size: 1em; display:none; ">
			<form id='myForm' name='myForm' method='post'>
			 <table>
				<tr>
					<td>
					Latitude:
					</td>
					<td>
					<input id="txtLat" name="Lat" class="text ui-widget-content ui-corner-all" readonly="readonly" type="text" size = "60" />
					</td>
				</tr>
				<tr>
					<td>
					Longitude:
					</td>
					<td>
					<input id="txtLng" name="Lng" type="text" class="text ui-widget-content ui-corner-all" readonly="readonly" size = "60"/>
					</td>
				</tr>
				<tr>
					<td>
					Tilte:
					</td>
					<td>
					<input id="txtTitle" name="Title" class="text ui-widget-content ui-corner-all" type="text" size = "60"/>
					</td>		
				</tr>
				<tr>
					<td>
					Description:
					</td>
					<td>
					<textarea  rows="5" cols="58" id="txtDescription"  name="Description" class="text ui-widget-content ui-corner-all"></textarea>
					
					</td>		
				</tr>
				<tr>
					<td>
					Price:(VND)
					</td>
					<td>
					<input id="txtPrice" name="Price" class="text ui-widget-content ui-corner-all"  type="text" size = "60"/>
					</td>		
				</tr>
                <tr>
					<td>
					&nbsp;
					</td>
					<td>
					    <div class='yeucau' id='chuso'></div>
					</td>
				</tr>
			
			 </table>
			
				<br/>
				<img src="<?php echo base_url(); ?>themes/home/images/Townhouse.png" alt="Townhouse" title="Townhouse Type"/>
				<input type="radio" onClick="CheckRadio(this)" checked="checked"
				title='Townhouse Type' name="house_type" id="Townhouse" />Townhouse
				&nbsp;&nbsp;&nbsp;&nbsp;		
				
				<img src="<?php echo base_url(); ?>themes/home/images/Condominium.png" alt="Condominium" title="Condominium Type"/>
				<input type="radio" onClick="CheckRadio(this)" 
				title='Condominium Type' name="house_type" id="Condominium" />Condominium
				&nbsp;&nbsp;&nbsp;&nbsp;
				
				<img src="<?php echo base_url(); ?>themes/home/images/Apartment.png" alt="Apartment" title="Apartment Type"/>
				<input type="radio" onClick="CheckRadio(this)" 
				title='Apartment Type' name="house_type" id="Apartment" />Apartment
				&nbsp;&nbsp;&nbsp;&nbsp;
				
				<img src="<?php echo base_url(); ?>themes/home/images/House.png" alt="House" title="House Type"/>
				<input type="radio" onClick="CheckRadio(this)" 
				title='House Type' name="house_type" id="House" />House
				
				<div id="upload" ><span>Upload File<span></div><span id="status" ></span>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;		
				<ul id="files" ></ul>
			</form>
		</div>
		

<!--right panel end -->
<br class="spacer" />

<!--body end -->
<script type="text/javascript">


var newarkcoords = [{ Longitude: "104.91853440295404", Latitude: "8.499182382002774" },{ Longitude: "104.78669846545404", Latitude: "8.575234547738026" },{ Longitude: "104.86360276232904", Latitude: "8.716433806995457" },{ Longitude: "104.83064377795404", Latitude: "9.020373067370087" },{ Longitude: "104.90754807482904", Latitude: "9.768257326383516" },{ Longitude: "105.03938401232904", Latitude: "9.844038017159397" },{ Longitude: "105.11628830920404", Latitude: "9.941444766249402" },{ Longitude: "104.78669846545404", Latitude: "10.146985616976927" },{ Longitude: "104.72078049670404", Latitude: "10.11454050051868" },{ Longitude: "104.61091721545404", Latitude: "10.146985616976927" },{ Longitude: "104.54499924670404", Latitude: "10.265922837527734" },{ Longitude: "104.50105393420404", Latitude: "10.374008807254025" },{ Longitude: "104.59993088732904", Latitude: "10.503662683701764" },{ Longitude: "104.88557541857904", Latitude: "10.49286026192908" },{ Longitude: "105.10530198107904", Latitude: "10.654856772446662" },{ Longitude: "105.14924729357904", Latitude: "10.92465895196993" },{ Longitude: "105.42390549670404", Latitude: "10.913871530504622" },{ Longitude: "105.79744065295404", Latitude: "10.98937523580191" },{ Longitude: "105.90730393420404", Latitude: "10.903083717403685" },{ Longitude: "106.02815354357904", Latitude: "10.870717931969882" },{ Longitude: "106.15998948107904", Latitude: "10.816767157916146" },{ Longitude: "106.19294846545404", Latitude: "10.957018862870969" },{ Longitude: "106.12703049670404", Latitude: "11.043294634893925" },{ Longitude: "105.90730393420404", Latitude: "11.248097661791633" },{ Longitude: "105.89631760607904", Latitude: "11.463522572331064" },{ Longitude: "105.85237229357904", Latitude: "11.614222526929217" },{ Longitude: "105.99519455920404", Latitude: "11.6572647453595" },{ Longitude: "106.09407151232904", Latitude: "11.732572563993234" },{ Longitude: "106.33577073107904", Latitude: "11.678783354785566" },{ Longitude: "106.42366135607904", Latitude: "11.6572647453595" },{ Longitude: "106.43464768420404", Latitude: "11.797105770359384" },{ Longitude: "106.40168869982904", Latitude: "11.926126573118799" },{ Longitude: "106.65437424670404", Latitude: "11.926126573118799" },{ Longitude: "106.83015549670404", Latitude: "12.044341777085108" },{ Longitude: "107.03889573107904", Latitude: "12.076573279461813" },{ Longitude: "107.32454026232904", Latitude: "12.280615650321872" },{ Longitude: "107.47834885607904", Latitude: "12.237672413694234" },{ Longitude: "107.57722580920404", Latitude: "12.452318315958701" },{ Longitude: "107.58821213732904", Latitude: "12.752523871926698" },{ Longitude: "107.50032151232904", Latitude: "12.956032756695183" },{ Longitude: "107.50032151232904", Latitude: "13.030967957513097" },{ Longitude: "107.65413010607904", Latitude: "13.448045606060555" },{ Longitude: "107.48933518420404", Latitude: "13.779052901137932" },{ Longitude: "107.41243088732904", Latitude: "13.94971280412967" },{ Longitude: "107.37947190295404", Latitude: "14.098936767148126" },{ Longitude: "107.44538987170404", Latitude: "14.343878208208475" },{ Longitude: "107.56623948107904", Latitude: "14.56728690330075" },{ Longitude: "107.52229416857904", Latitude: "14.747976070633145" },{ Longitude: "107.58821213732904", Latitude: "14.843574470999465" },{ Longitude: "107.47834885607904", Latitude: "14.939130616800702" },{ Longitude: "107.55525315295404", Latitude: "15.066472655065526" },{ Longitude: "107.68708909045404", Latitude: "15.236143495504844" },{ Longitude: "107.41243088732904", Latitude: "15.448039591136798" },{ Longitude: "107.22566330920404", Latitude: "15.723180689103105" },{ Longitude: "107.18171799670404", Latitude: "15.797193913596017" },{ Longitude: "107.45637619982904", Latitude: "15.945139130621198" },{ Longitude: "107.37947190295404", Latitude: "16.040189234268848" },{ Longitude: "107.15974534045404", Latitude: "16.166852177918567" },{ Longitude: "106.97297776232904", Latitude: "16.314523041581733" },{ Longitude: "106.89607346545404", Latitude: "16.483153386082996" },{ Longitude: "106.76423752795404", Latitude: "16.409395585981407" },{ Longitude: "106.59944260607904", Latitude: "16.60952992845099" },{ Longitude: "106.55549729357904", Latitude: "16.95663528811756" },{ Longitude: "106.30281174670404", Latitude: "17.229662070159875" },{ Longitude: "105.65461838732904", Latitude: "17.86863368567535" },{ Longitude: "105.56672776232904", Latitude: "18.077637737440217" },{ Longitude: "105.34700119982904", Latitude: "18.150730558399847" },{ Longitude: "105.19319260607904", Latitude: "18.33854296415761" },{ Longitude: "105.12727463732904", Latitude: "18.494897666491717" },{ Longitude: "105.18220627795404", Latitude: "18.588642109946075" },{ Longitude: "105.06135666857904", Latitude: "18.723959674108308" },{ Longitude: "103.95173752795404", Latitude: "19.26414093103312" },{ Longitude: "103.87483323107904", Latitude: "19.26414093103312" },{ Longitude: "104.16047776232904", Latitude: "19.492147530702265" },{ Longitude: "103.98469651232904", Latitude: "19.60603075904481" },{ Longitude: "104.09455979357904", Latitude: "19.657769250898305" },{ Longitude: "104.32527268420404", Latitude: "19.647422886073358" },{ Longitude: "104.45710862170404", Latitude: "19.678459978168775" },{ Longitude: "104.66584885607904", Latitude: "19.58533069901832" },{ Longitude: "104.76472580920404", Latitude: "19.750856467757682" },{ Longitude: "104.87458909045404", Latitude: "19.895550855608477" },{ Longitude: "104.96247971545404", Latitude: "20.060754039482557" },{ Longitude: "104.88557541857904", Latitude: "20.163917866466576" },{ Longitude: "104.68782151232904", Latitude: "20.20516432714037" },{ Longitude: "104.44612229357904", Latitude: "20.39063793757863" },{ Longitude: "104.44612229357904", Latitude: "20.45241302198907" },{ Longitude: "104.57795823107904", Latitude: "20.493582621290635" },{ Longitude: "104.63288987170404", Latitude: "20.61702502461768" },{ Longitude: "104.41316330920404", Latitude: "20.750641460984287" },{ Longitude: "104.17146409045404", Latitude: "20.884139943040445" },{ Longitude: "103.94075119982904", Latitude: "20.853343102847077" },{ Longitude: "103.81990159045404", Latitude: "20.668429881135317" },{ Longitude: "103.44636643420404", Latitude: "20.740367453376514" },{ Longitude: "103.10579026232904", Latitude: "20.843076087514515" },{ Longitude: "102.94099534045404", Latitude: "21.068788111649177" },{ Longitude: "102.82014573107904", Latitude: "21.242967841875373" },{ Longitude: "102.84211838732904", Latitude: "21.416941975607727" },{ Longitude: "102.94099534045404", Latitude: "21.60092427821025" },{ Longitude: "102.88606369982904", Latitude: "21.66219987518087" },{ Longitude: "102.79817307482904", Latitude: "21.63156532515403" },{ Longitude: "102.58943284045404", Latitude: "21.67240994682166" },{ Longitude: "102.55647385607904", Latitude: "21.88665402510366" },{ Longitude: "102.28181565295404", Latitude: "22.202331054747575" },{ Longitude: "102.18293869982904", Latitude: "22.35482422753197" },{ Longitude: "102.34773362170404", Latitude: "22.517299819367796" },{ Longitude: "102.49055588732904", Latitude: "22.730259336191338" },{ Longitude: "102.69929612170404", Latitude: "22.689721070277603" },{ Longitude: "103.06184494982904", Latitude: "22.466546640328005" },{ Longitude: "103.20466721545404", Latitude: "22.557888949758745" },{ Longitude: "103.24861252795404", Latitude: "22.64917080896872" },{ Longitude: "103.36946213732904", Latitude: "22.750523965643033" },{ Longitude: "103.47932541857904", Latitude: "22.709991703705715" },{ Longitude: "103.55622971545404", Latitude: "22.608608569032423" },{ Longitude: "103.64412034045404", Latitude: "22.79104420708795" },{ Longitude: "103.81990159045404", Latitude: "22.69985676197868" },{ Longitude: "103.99568284045404", Latitude: "22.557888949758745" },{ Longitude: "104.08357346545404", Latitude: "22.750523965643033" },{ Longitude: "104.24836838732904", Latitude: "22.841677579645257" },{ Longitude: "104.38020432482904", Latitude: "22.760655153578075" },{ Longitude: "104.45710862170404", Latitude: "22.720125895197096" },{ Longitude: "104.58894455920404", Latitude: "22.821426489679162" },{ Longitude: "104.76472580920404", Latitude: "22.841677579645257" },{ Longitude: "104.80867112170404", Latitude: "22.983350686951056" },{ Longitude: "104.92952073107904", Latitude: "23.14508102731277" },{ Longitude: "105.27009690295404", Latitude: "23.33688256426784" },{ Longitude: "105.41291916857904", Latitude: "23.367141776672295" },{ Longitude: "105.63264573107904", Latitude: "23.165283636668878" },{ Longitude: "105.95124924670404", Latitude: "22.932770149991928" },{ Longitude: "106.20393479357904", Latitude: "23.00357760275346" },{ Longitude: "106.37971604357904", Latitude: "22.922651773678" },{ Longitude: "106.77522385607904", Latitude: "22.88217071398452" },{ Longitude: "106.90705979357904", Latitude: "22.750523965643033" },{ Longitude: "106.69831955920404", Latitude: "22.48685014557077" },{ Longitude: "106.77522385607904", Latitude: "22.273515226627758" },{ Longitude: "106.80818284045404", Latitude: "22.059854461283525" },{ Longitude: "106.95100510607904", Latitude: "21.957997431229987" },{ Longitude: "107.11580002795404", Latitude: "21.805074988409267" },{ Longitude: "107.62117112170404", Latitude: "21.60092427821025" },{ Longitude: "107.89582932482904", Latitude: "21.621352364354465" },{ Longitude: "108.22541916857904", Latitude: "21.427169316421228" },{ Longitude: "107.66511643420404", Latitude: "21.15078056745551" },{ Longitude: "107.31355393420404", Latitude: "20.914930468613946" },{ Longitude: "106.95100510607904", Latitude: "20.863609417400077" },{ Longitude: "106.95100510607904", Latitude: "20.791730509027193" },{ Longitude: "106.67634690295404", Latitude: "20.48329125702525" },{ Longitude: "106.63240159045404", Latitude: "20.287624455158674" },{ Longitude: "106.13801682482904", Latitude: "19.885219914359496" },{ Longitude: "105.91829026232904", Latitude: "19.66811494836153" },{ Longitude: "105.86335862170404", Latitude: "19.33672308190894" },{ Longitude: "105.75349534045404", Latitude: "19.035816779987368" },{ Longitude: "105.73152268420404", Latitude: "18.796778189041287" },{ Longitude: "105.90730393420404", Latitude: "18.484478444429712" },{ Longitude: "106.11604416857904", Latitude: "18.2342277893834" },{ Longitude: "106.44563401232904", Latitude: "18.056748476864215" },{ Longitude: "106.55549729357904", Latitude: "17.84771970495665" },{ Longitude: "106.59944260607904", Latitude: "17.575615160990303" },{ Longitude: "107.12678635607904", Latitude: "17.01967693393838" },{ Longitude: "107.47834885607904", Latitude: "16.64111110247582" },{ Longitude: "108.00569260607904", Latitude: "16.303978803721304" },{ Longitude: "108.31330979357904", Latitude: "16.029630344921" },{ Longitude: "108.52205002795404", Latitude: "15.680875321512964" },{ Longitude: "108.79670823107904", Latitude: "15.373900429402157" },{ Longitude: "108.96150315295404", Latitude: "15.214942090326259" },{ Longitude: "108.99446213732904", Latitude: "14.864812830400625" },{ Longitude: "109.14827073107904", Latitude: "14.290652677454263" },{ Longitude: "109.32405198107904", Latitude: "13.843065060420729" },{ Longitude: "109.53279221545404", Latitude: "12.85965437513175" },{ Longitude: "109.44490159045404", Latitude: "12.355749444505319" },{ Longitude: "109.31306565295404", Latitude: "12.012106405564102" },{ Longitude: "109.17024338732904", Latitude: "11.463522572331064" },{ Longitude: "108.79670823107904", Latitude: "11.118765149289572" },{ Longitude: "108.24739182482904", Latitude: "10.795184127480109" },{ Longitude: "107.81892502795404", Latitude: "10.5576691212259" },{ Longitude: "107.13777268420404", Latitude: "10.330778876237984" },{ Longitude: "106.86311448107904", Latitude: "10.330778876237984" },{ Longitude: "106.67634690295404", Latitude: "9.746602524735751" },{ Longitude: "106.45662034045404", Latitude: "9.454126323289021" },{ Longitude: "105.90730393420404", Latitude: "9.161401297821742" },{ Longitude: "105.54475510607904", Latitude: "8.987820231976562" },{ Longitude: "105.29206955920404", Latitude: "8.672993522211963" },{ Longitude: "105.08332932482904", Latitude: "8.54264261838538" },{ Longitude: "104.84163010607904", Latitude: "8.488316552135478" }];
	function showTxt()
	{
		if(jQuery('#slidingDiv').css('display')!='block')
		{
			jQuery('#slidingDiv').show(1000);
			resizeImg();
		}
		
	}
	function hideTxt()
	{
		if(jQuery('#slidingDiv').css('display')!='none')
			jQuery('#slidingDiv').hide('slow');
	}		
	function changeImg(obj)
	{
		jQuery('#largimg').attr('src',jQuery(obj).attr('src'));
		resizeImg();
	}
    var map;		
	var infowindow;
	var markers = [];
	function createTooltip(marker, contentSample) 
	{
		//create a tooltip 
		var tooltipOptions={
			marker:marker,
			content:contentSample,
			cssClass:'tooltip' // name of a css class to apply to tooltip
		};
		var tooltip = new Tooltip(tooltipOptions);
    }
	//
	map = new google.maps.Map(document.getElementById("map_canvas"), {
		center: new google.maps.LatLng(21.027714828439812, 105.85262978564452),
		zoom: 16,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});

	jQuery(document).ready(function () {
	        var latlng = new google.maps.LatLng(21.027714828439812, 105.85262978564452);
	        var myOptions = {
	            zoom: 16,
	            center: latlng,
	            mapTypeId: google.maps.MapTypeId.ROADMAP
	        };
	        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
			
	        var NewarkHighlight;
	        var mNewarkCoords = new Array;

	        for (var i = 0; i < newarkcoords.length; i++) {
	            mNewarkCoords[i] = new google.maps.LatLng(newarkcoords[i].Latitude, newarkcoords[i].Longitude);
	        }
	        // Construct the polygon
	        // Note that we don't specify an array or arrays, but instead just
	        // a simple array of LatLngs in the paths property
	        NewarkHighlight = new google.maps.Polygon({
	            paths: mNewarkCoords,
	            strokeColor: "#EC1928",
	            strokeOpacity: 1,
	            strokeWeight: 4,
	            fillColor: "#6666FF",
	            fillOpacity: 0
	        });
	        NewarkHighlight.setMap(map);

	    });
  //Keep track of where you clicked
	var clickedLatLng;
	var longitude;
	var latitude;
	// Display and position the menu
	google.maps.event.addListener(map, 'rightclick', function(e)
	{
		// start buy hiding the context menu if its open
		latitude = e.latLng.lat();
		longitude = e.latLng.lng();
		
		//alert('{ Longitude: "'+longitude+'", Latitude: "'+latitude+'" }');
		//jQuery('#tdf').append('{ Longitude: "'+longitude+'", Latitude: "'+latitude+'" },');
		var mapDiv = jQuery(map.getDiv()),
			x = e.pixel.x,
			y = e.pixel.y;
		// save the clicked location
		clickedLatLng = e.latLng;
		//alert(x);
		
		// adjust if clicked to close to the edge of the map
		//   if ( x > mapDiv.width() - contextMenu.width() )
		//	x -= contextMenu.width();

		   //if ( y > mapDiv.height() - contextMenu.height() )
		//	y -= contextMenu.height();

		   // Set the location and fade in the context menu
		  // contextMenu.css({ top: y, left: x }).fadeIn(100);

		
		
	});
	//Menu right click
	jQuery(document).ready( function() 
	{
		
		checkHomeSession();
		
		  jQuery("#map_canvas").contextMenu({
					menu: 'mypopup'
				},
				function(action, el, pos) 
				{
					
					switch ( action )
					{
						case 'addPlace':
							
							jQuery('#txtLat').val(latitude);
							jQuery('#txtLng').val(longitude);
							jQuery('#txtTitle').val("");
							jQuery('#txtDescription').val("");
							jQuery('#txtPrice').val("");
							CheckRadio(document.getElementById('Townhouse'));
							//houseType = "Townhouse";
							jQuery('#files').empty();
							jQuery('#dialog').dialog({
							autoOpen: true,
							width: 600,
							buttons: {
								"Ok": function() 
								{
										var method={act:'add'};
										var myJSONtext=jQuery('#myForm').toJSON();
										var type={houseType:houseType};
										var output = {};
										var jsona = {};
										output = jsonConcat(output, myJSONtext);
										output = jsonConcat(output, method);
										output = jsonConcat(output, type);
										var collection = document.getElementsByName('uploadPic');
										if (collection.length > 0)
										{	
											for (var i=0; i<collection.length; i++) 
											{
												jsona['Img'+(i + 1)] =  collection[i].getAttribute('alt');
											}
										}	
										output = jsonConcat(output, jsona);
																	
										jQuery.ajax({
											url: '<?php echo base_url(); ?>index/process',
											dataType: "json",
											data:output,
											type: "POST",
											async: true,
											success: function(msg) 
											{
												if(msg.ret=='success')
												{
										    	   alert('Thanh cong');
												}
												else
												{
													alert('Khong thanh cong!');
												}	
											}
										});
									jQuery("#gwidth").setGridParam({url:'<?php echo base_url(); ?>index/getAll'});
									jQuery("#gwidth").clearGridData();
									jQuery("#gwidth").trigger("reloadGrid");
									var point2 = new google.maps.LatLng(jQuery('#txtLat').val(), jQuery('#txtLng').val());					
									map.setCenter(point2, 16);	

									jQuery(this).dialog("close");
								},//end ok function
								"Cancel": function() {
									jQuery(this).dialog("close");
								}
							}
						});
							break;

						case 'zoomIn':
							map.setZoom(
								map.getZoom() + 1
							);
							map.panTo(clickedLatLng);
							break;

						case 'zoomOut':
							map.setZoom(
								map.getZoom() - 1
							);
							map.panTo(clickedLatLng);
							break;

						case 'centerHere':
							map.panTo(clickedLatLng);
							break;
					}//End swift
							
			});
	
		 
	});//end ready function		
</script>


<script type="text/javascript">


function postwith (to,p) {
	  var myForm = document.createElement("form");
	  myForm.method="post" ;
	  myForm.action = to ;
	  for (var k in p) {
	    var myInput = document.createElement("input") ;
	    myInput.setAttribute("name", k) ;
	    myInput.setAttribute("value", p[k]);
	    myForm.appendChild(myInput) ;
	  }
	  document.body.appendChild(myForm) ;
	  myForm.submit() ;
	  document.body.removeChild(myForm) ;
	}
	
var houseType = "Townhouse";
function CheckRadio(element)
{
	document.getElementById('Townhouse').checked=false;
	document.getElementById('Condominium').checked=false;
	document.getElementById('Apartment').checked=false;
	document.getElementById('Apartment').checked=false;
	element.checked = true;
	houseType = element.id;
}


var myOptions = {
		 //content: boxText
		disableAutoPan: false
		,maxWidth: 0
		,pixelOffset: new google.maps.Size(-140, 0)
		,zIndex: null
		,boxStyle: { 
		  background: "url('../themes/home/images/tipbox.gif') no-repeat"
		  ,opacity: 1
		  ,width: "550px"
		  ,height: "450px"
		 }
		,closeBoxMargin: "10px 5px 5px 5px"
		,closeBoxURL: "../themes/home/images/close.png"
		,infoBoxClearance: new google.maps.Size(1, 1)
		,isHidden: false
		,pane: "floatPane"
		,enableEventPropagation: false
	};
var ib= new InfoBox(myOptions);
 function closeMe()
 {
	 if (ib) ib.close();
 }
 function resizeImg()
{
	 //largImg

	 jQuery('#largimg').each(function() {
	        var maxWidth = 398; // Max width for the image
	        var maxHeight = 298;    // Max height for the image
	        var ratio = 0;  // Used for aspect ratio
	        var width = jQuery(this).width();    // Current image width
	        var height = jQuery(this).height();  // Current image height
	        // Check if the current width is larger than the max
	        if(width > height){
	            height = ( height / width ) * maxHeight;

	        } else if(height > width){
	            maxWidth = (width/height)* maxWidth;
	        }
	        jQuery(this).css("width", maxWidth); // Set new width
	        jQuery(this).css("height", maxHeight);  // Scale height based on ratio
	    });
}
function bindInfoW(marker, contentString, infowindow, point, id,price)
{
	if (ib) ib.close();
       google.maps.event.addListener(marker, 'click', function() 
        {
    	   var zindex=jQuery.maxZIndex()+1;
    	    var method={act:'viewOne',id:id};			
			jQuery.ajax
		    ({
		        type: "POST",
		        url: '<?php echo base_url(); ?>index/getOnePlace',
		        dataType: 'json',
		        async: true,
		        data:method
		        ,success:function(msg)
		        {	 
	        	    var aas=msg.message;
		        	var b='<div id="myTip" style="margin-top: 8px; background: #FFF; padding: 5px;-moz-box-shadow: inset -5px -5px 5px #888;-webkit-box-shadow: inset -5px -5px 5px #888;box-shadow: inset -5px -5px 5px #888;-moz-border-radius: 10px;border-radius: 10px;z-index:'+zindex+';">';
		        	ib.setContent(b+aas);
			    } 
		    });
			ib.open(map, this); 
				  
        });	
       google.maps.event.addListener(marker, "mouseover", function(event) 
       {
           this.setIcon("<?php echo base_url(); ?>themes/home/images/homeout.png");   
       });
       google.maps.event.addListener(marker, "mouseout", function(event) 
       {
    	           this.setIcon("<?php echo base_url(); ?>themes/home/images/home.png");   
       });
      
              
}
jQuery(document).ready(function(){
	jQuery("#txtPrice").blur(function()
		{
		   var num=jQuery("#txtPrice").val().replace(/,/g,"");
		   jQuery("#chuso").html(DocTienBangChu(num));
		   jQuery("#txtPrice").formatCurrency();
		});
	jQuery("#txtPrice").keyup(function()
	{
		var num=jQuery("#txtPrice").val().replace(/,/g,"");
		jQuery("#chuso").html(DocTienBangChu(num));
	});
	
	
	jQuery("#gwidth").jqGrid({
	url:'<?php echo base_url(); ?>index/getAll'
	, datatype: "json",
	mtype: "POST",
   	colNames:['Id','','','Title', 'Price',''],
   	colModel:[
   		{name:'id',index:'id', width:55},
   		{name:'lat',index:'lat', width:1, hidden:true},
   		{name:'lng',index:'lng', width:1, hidden:true},
   		{name:'title',index:'title', width:100},
   		{name:'price',index:'price', width:80, align:"right"},
		{name:'housetype',index:'housetype', width:1, hidden:true}
   	   	],
   	rowNum:1000,
   	/*rowList:[10,20,30],*/
   	pager: '#pgwidth',
   	/*sortname: 'id',*/
/*    viewrecords: true,*/
    sortorder: "desc",
    caption:"Places to go",
	forceFit : true,
	/*forceFit : true*/
	gridComplete: function()
		{ 
			var ids = jQuery("#gwidth").jqGrid('getDataIDs'); 
			for (var i = 0; i < markers.length; i++) {
         			 markers[i].setMap(null);
		        }
			 markers = [];
		       for(var i=0;i < ids.length;i++)
		       { 
		        	var cl = ids[i];
		        	var ret = jQuery("#gwidth").jqGrid('getRowData',cl);
		        	
		        	var lblLat = ret.lat;
		        	var lblLng = ret.lng;
		        	var lblTitle = ret.title;
					var id = ret.id;
					var point = new google.maps.LatLng(lblLat, lblLng);
					var housetype = ret.housetype;
					if (housetype == '' || housetype ==null)
						housetype = 'default';
	

				/*
				   var marker = new google.maps.Marker({
      				  position: new google.maps.LatLng(lblLat, lblLng),
					   icon: '<?php echo base_url(); ?>themes/home/images/' + housetype + '.png',
       				 map: map
     				 });
   				 */
				     var priceDisplay=ret.price;
				     if(priceDisplay>=1000000000)
				     {
				    	 priceDisplay=(priceDisplay/1000000000).toFixed(2)+'B';
	                     priceDisplay=priceDisplay.replace('.',',');
				    	   
				     }else
				     {
					     if(priceDisplay>=1000000)
					     {
					    	 priceDisplay=(priceDisplay/1000000).toFixed(1)+'M';
					    	 priceDisplay=priceDisplay.replace('.',',');
						 }else
						 {
							 priceDisplay=(priceDisplay/1000).toFixed(0)+'K';
							 priceDisplay=priceDisplay.replace('.',',');
					     }
				     }
					 var marker = new MarkerWithLabel({
	      				  position: new google.maps.LatLng(lblLat, lblLng),
						   icon: '<?php echo base_url(); ?>themes/home/images/home.png',
						    draggable: false,
							raiseOnDrag: true,
							labelContent: priceDisplay,
							labelAnchor: new google.maps.Point(22, 43),
							labelClass: "labels", // the CSS class for the label
							labelStyle: {opacity: 1.0}	,
							map: map
	     				 });
 				 
				// createTooltip(marker, "<iframe src='detail.php?id=" + ret.id +"'></iframe>");
				markers.push(marker);
				bindInfoW(marker, lblTitle, infowindow, point, ret.id,ret.price);	
				
		      } 
		  }
	});
	jQuery("#gwidth").jqGrid('navGrid','#pgwidth',{edit:false,add:false,del:false});
	
	var myWidth;
	var myHeight;
	
	if( typeof( window.innerWidth ) == 'number' ) { 
	
	//Non-IE 
	
	myWidth = window.innerWidth;
	myHeight = window.innerHeight; 
	
	} else if( document.documentElement && 
	
	( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 
	
	//IE 6+ in 'standards compliant mode' 
	
	myWidth = document.documentElement.clientWidth; 
	myHeight = document.documentElement.clientHeight; 
	
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
	
	//IE 4 compatible 
	
	myWidth = document.body.clientWidth; 
	myHeight = document.body.clientHeight; 
	
	} 
	jQuery("#gwidth").jqGrid('setGridHeight',myHeight - 400);
});
/*---------------Upload File-------------------------------------------------------*/
jQuery(function(){
	var btnUpload=jQuery('#upload');
	var status=jQuery('#status');
	new AjaxUpload(btnUpload, {
		action: '<?php echo base_url(); ?>index/process',
		name: 'uploadfile',
		data:{act:'upload',key:randomString()},
		onSubmit: function(file, ext){
			var uploadFilesCount = jQuery("#files li").size() ;
			if (uploadFilesCount >=5)
				return false;
			 //if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                // extension is not allowed 
			//	status.text('Only JPG, PNG or GIF files are allowed');
			//	return false;
			//}
			status.text('Uploading...');
		},
		onComplete: function(file, response)
		{
			//On completion clear the status
			status.text('');
			//Add uploaded file to list
			if(response!=="error"){
				jQuery('<li></li>').appendTo('#files').html('<img name="uploadPic" alt="'+response+'" src="<?php echo base_url()?>themes/home/uploads/'+response+'" alt="" /><br />'+file).addClass('success');
			} else{
				jQuery('<li></li>').appendTo('#files').text(file).addClass('error');
			}
		}
	});
	
});
/*---------------Upload File-------------------------------------------------------*/
</script>
<?php $this->load->view('home/common/body'); ?>
<?php $this->load->view('home/common/footer'); ?>
